package com.fyzk.activity.user;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.interfaces.ReTryInterface;
import com.tyjc.lottery.R;

import http.DataUtil.text.TextUtil;

/**
 * 联网等待和联网后界面
 * 
 * @author fl
 * 
 */
public class NetProgressView extends LinearLayout implements OnClickListener {
	
	private Context context;

	LinearLayout linear_loading;
	LinearLayout linear_fail;
	LinearLayout linear_norecord;

	Button btn_retry;
	TextView noneMessageTv;
	TextView error_msg;

	public NetProgressView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.context = context;
		initView();

		// TODO Auto-generated constructor stub
	}

	public NetProgressView(Context context, AttributeSet attrs) {
		// TODO Auto-generated constructor stub
		super(context, attrs);
		this.context = context;
		initView();
	}

	public NetProgressView(Context context) {
		// TODO Auto-generated constructor stub
		super(context);
		this.context = context;
		initView();
	}
	
	private void initView(){
		View.inflate(context, R.layout.net_progress_view, this);
		if(isInEditMode()){
			return;
		}
		noneMessageTv = (TextView)findViewById(R.id.noneMessage);
		error_msg = (TextView)findViewById(R.id.error_msg);
		linear_loading = (LinearLayout) findViewById(R.id.dj_netprogress_waiting);
		linear_fail = (LinearLayout) findViewById(R.id.dj_netprogress_fail);
		linear_fail.setOnClickListener(this);
		linear_norecord = (LinearLayout) findViewById(R.id.dj_netprogress_norecord);
	}

	/**
	 * 开始联网进度条
	 */
	public void waiting() {
		this.setVisibility(View.VISIBLE);
		linear_loading.setVisibility(View.VISIBLE);
		linear_fail.setVisibility(View.GONE);
		linear_norecord.setVisibility(View.GONE);
	}

	/**
	 * 开始联网进度条
	 */
	public void dismiss() {
		linear_loading.setVisibility(View.GONE);
		linear_fail.setVisibility(View.GONE);
		linear_norecord.setVisibility(View.GONE);
	}

	//
	/**
	 * 联网失败界面可以见
	 */
	public void fail(String msg) {
		linear_loading.setVisibility(View.GONE);
		linear_fail.setVisibility(View.VISIBLE);
		linear_norecord.setVisibility(View.GONE);
		error_msg.setText(msg);
	}

	private ReTryInterface retryInterface = null;

	public void setRetryInterface(ReTryInterface retryInterface) {

		this.retryInterface = retryInterface;
	}

//	/**
//	 * 联网成功没有记录界面可见
//	 */
//	public void noneRecord() {
//		linear_loading.setVisibility(View.GONE);
//		linear_fail.setVisibility(View.GONE);
//		linear_norecord.setVisibility(View.VISIBLE);
//	}
	/**
	 * 联网成功没有记录界面可见
	 */
	public void noneRecord(String noneMessage) {
		if(!TextUtil.isEmpty(noneMessage)){
			this.noneMessageTv.setText(noneMessage);
		}
		linear_loading.setVisibility(View.GONE);
		linear_fail.setVisibility(View.GONE);
		linear_norecord.setVisibility(View.VISIBLE);
	}

	
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.dj_netprogress_fail:
			if (retryInterface != null) {
				retryInterface.reTry();
			}
			break;

		default:
			break;
		}

	}
}